<!DOCTYPE html>
<html>

<head>
    <title>Example</title>
    <!-- lifehacker.com-------js启蒙读物
        使用说明参见:http://lifehacker.com/5744113/learn-to-code-the-full-beginners-guide
        《JavaScript权威指南(第六版)》, 机械工业出版社
        《JavaScript设计模式》, 人民邮电出版社
    -->
</head>

<body>
    <!-- script位于文档中其他内容之后, 
        这样一来在脚本执行之前浏览器就已经对其他元素进行了解析 -->
    <script type="text/javascript">
        var myData = new Object();
        //这种对象属性赋值方式和Java不一样, 挠头
        myData.name = "Adam";
        myData.weather = "sunny";
        document.writeln("Hello " + myData.name + ".");
        document.writeln("Today is " + myData.weather + " .");

        var MyData = {
            name: "Adam",
            weather: "sunny",
            printMessages: function () {
                document.writeln("Hello " + this.name + ".");
                document.writeln("Today is " + this.weather + " .");
            }
        };
        MyData.printMessages();

        MyData.name = "Joe";
        MyData["weather"] = "raining";
        document.writeln("Hello " + MyData.name + ".");
        document.writeln("Today is " + MyData.weather + " .");

        for (var prop in MyData){
            document.writeln("Name: " + prop + " Value: " + MyData[prop]);
        }

        // 添加属性
        MyData.dayOfWeek = "Monday";
        MyData.sayHello = function () {
            document.writeln("Hello");
        }

        // 是否有某个属性
        var hasName = "name" in MyData;
        var hasDate = "date" in MyData;
        document.writeln("HasName: " + hasName);
        document.writeln("HasDate: " + hasDate);
        // 删除属性
        delete MyData.name;
        delete MyData["weather"];
        delete MyData.sayHello;

    </script>
</body>

</html>